<template>
  <div class="member-benefits">
    <h2 class="benefits-title">{{ title }}</h2>
    
    <div class="benefits-container">
      <!-- 黄金会员 -->
      <div class="benefit-card gold" :class="{ 'selected': selectedLevel === 1 }">
        <div class="benefit-header">
          <div class="badge gold">黄金会员</div>
          <div class="price">¥{{ goldPrice }}/月</div>
        </div>
        <div class="benefit-body">
          <ul class="benefit-list">
            <li v-for="benefit in goldBenefits" :key="benefit.id" class="benefit-item">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" class="check-icon">
                <path d="M9 16.17L4.83 12L3.41 13.41L9 19L21 7L19.59 5.59L9 16.17Z" fill="#ff9800"/>
              </svg>
              {{ benefit.description }}
            </li>
          </ul>
        </div>
        <div class="benefit-footer">
          <button 
            class="select-btn" 
            @click="selectPlan(1)"
            :disabled="selectedLevel === 1"
          >
            {{ selectedLevel === 1 ? '已选择' : '选择方案' }}
          </button>
        </div>
      </div>
      
      <!-- 铂金会员 -->
      <div class="benefit-card platinum" :class="{ 'selected': selectedLevel === 2 }">
        <div class="benefit-header">
          <div class="badge platinum">铂金会员</div>
          <div class="price">¥{{ platinumPrice }}/月</div>
          <div class="recommended-badge">推荐</div>
        </div>
        <div class="benefit-body">
          <ul class="benefit-list">
            <li v-for="benefit in platinumBenefits" :key="benefit.id" class="benefit-item">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" class="check-icon">
                <path d="M9 16.17L4.83 12L3.41 13.41L9 19L21 7L19.59 5.59L9 16.17Z" fill="#2196f3"/>
              </svg>
              {{ benefit.description }}
            </li>
          </ul>
        </div>
        <div class="benefit-footer">
          <button 
            class="select-btn" 
            @click="selectPlan(2)"
            :disabled="selectedLevel === 2"
          >
            {{ selectedLevel === 2 ? '已选择' : '选择方案' }}
          </button>
        </div>
      </div>
      
      <!-- 钻石会员 -->
      <div class="benefit-card diamond" :class="{ 'selected': selectedLevel === 3 }">
        <div class="benefit-header">
          <div class="badge diamond">钻石会员</div>
          <div class="price">¥{{ diamondPrice }}/月</div>
        </div>
        <div class="benefit-body">
          <ul class="benefit-list">
            <li v-for="benefit in diamondBenefits" :key="benefit.id" class="benefit-item">
              <svg width="16" height="16" viewBox="0 0 24 24" fill="none" class="check-icon">
                <path d="M9 16.17L4.83 12L3.41 13.41L9 19L21 7L19.59 5.59L9 16.17Z" fill="#9c27b0"/>
              </svg>
              {{ benefit.description }}
            </li>
          </ul>
        </div>
        <div class="benefit-footer">
          <button 
            class="select-btn" 
            @click="selectPlan(3)"
            :disabled="selectedLevel === 3"
          >
            {{ selectedLevel === 3 ? '已选择' : '选择方案' }}
          </button>
        </div>
      </div>
    </div>
    
    <div class="benefit-summary" v-if="selectedLevel > 0">
      <h3>已选择: {{ getLevelName(selectedLevel) }}</h3>
      <p>价格: ¥{{ getPrice(selectedLevel) }}/月</p>
      <button class="proceed-btn" @click="proceedToPayment">继续支付</button>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps({
  title: {
    type: String,
    default: '会员权益'
  },
  goldPrice: {
    type: Number,
    default: 19.9
  },
  platinumPrice: {
    type: Number,
    default: 39.9
  },
  diamondPrice: {
    type: Number,
    default: 89.9
  }
});

const emit = defineEmits(['planSelected', 'proceed']);

const selectedLevel = ref(0);

// 黄金会员权益
const goldBenefits = [
  { id: 1, description: '无广告浏览体验' },
  { id: 2, description: '每月可发布10篇优质内容' },
  { id: 3, description: '获得专属会员徽章' },
  { id: 4, description: '评论区优先展示' },
  { id: 5, description: '每月50积分奖励' }
];

// 铂金会员权益（包含黄金会员的所有权益）
const platinumBenefits = [
  ...goldBenefits,
  { id: 6, description: '每月可发布20篇优质内容' },
  { id: 7, description: '内容曝光量提升30%' },
  { id: 8, description: '专属客服通道' },
  { id: 9, description: '每月100积分奖励' },
  { id: 10, description: '专属活动优先参与权' }
];

// 钻石会员权益（包含铂金会员的所有权益）
const diamondBenefits = [
  ...platinumBenefits,
  { id: 11, description: '无限发布内容' },
  { id: 12, description: '内容曝光量提升100%' },
  { id: 13, description: '专属内容审核通道' },
  { id: 14, description: '每月200积分奖励' },
  { id: 15, description: '平台分红资格' },
  { id: 16, description: '定制化个人主页' }
];

const selectPlan = (level) => {
  selectedLevel.value = level;
  emit('planSelected', level);
};

const proceedToPayment = () => {
  emit('proceed', {
    level: selectedLevel.value,
    price: getPrice(selectedLevel.value)
  });
};

const getLevelName = (level) => {
  switch(level) {
    case 1: return '黄金会员';
    case 2: return '铂金会员';
    case 3: return '钻石会员';
    default: return '';
  }
};

const getPrice = (level) => {
  switch(level) {
    case 1: return props.goldPrice;
    case 2: return props.platinumPrice;
    case 3: return props.diamondPrice;
    default: return 0;
  }
};
</script>

<style scoped>
.member-benefits {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.benefits-title {
  text-align: center;
  margin-bottom: 40px;
  color: #333;
  font-size: 28px;
}

.benefits-container {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 40px;
}

.benefit-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  width: 300px;
  position: relative;
}

.benefit-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.benefit-card.selected {
  border: 2px solid #4caf50;
  transform: translateY(-5px);
}

.benefit-card.gold {
  border: 2px solid #ff9800;
}

.benefit-card.platinum {
  border: 2px solid #2196f3;
  transform: scale(1.05);
  z-index: 1;
}

.benefit-card.diamond {
  border: 2px solid #9c27b0;
}

.benefit-header {
  text-align: center;
  margin-bottom: 20px;
  position: relative;
}

.badge {
  font-size: 18px;
  font-weight: bold;
  padding: 8px 16px;
  border-radius: 20px;
  margin-bottom: 12px;
  display: inline-block;
}

.badge.gold {
  background: linear-gradient(135deg, #ff9800, #ffb74d);
  color: #fff;
}

.badge.platinum {
  background: linear-gradient(135deg, #2196f3, #64b5f6);
  color: #fff;
}

.badge.diamond {
  background: linear-gradient(135deg, #9c27b0, #ba68c8);
  color: #fff;
}

.price {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.recommended-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  background: #ff5722;
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
}

.benefit-body {
  margin-bottom: 24px;
}

.benefit-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.benefit-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.check-icon {
  margin-top: 2px;
}

.benefit-footer {
  text-align: center;
}

.select-btn {
  background: #4caf50;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
}

.select-btn:hover:not(:disabled) {
  background: #45a049;
}

.select-btn:disabled {
  background: #8bc34a;
  cursor: not-allowed;
}

.benefit-summary {
  background: #f5f5f5;
  padding: 24px;
  border-radius: 12px;
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
}

.benefit-summary h3 {
  margin: 0 0 12px 0;
  color: #333;
}

.benefit-summary p {
  margin: 0 0 20px 0;
  color: #666;
  font-size: 18px;
}

.proceed-btn {
  background: linear-gradient(135deg, #2196f3, #03a9f4);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 16px;
}

.proceed-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(33, 150, 243, 0.3);
}
</style>